package com.leapp.sk.viewdelegate.task

import android.support.v4.content.ContextCompat
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.NoScrollGridView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.CompleteTaskEntity
import com.leapp.sk.ui.activity.task.TaskCorrectActivity
import com.leapp.sk.ui.adapter.CompleteTaskAdapter

/**
 * 作业批改
 * @author  chaohaipeng  on 2018/8/13.
 */
class TaskCorrectDelegate :BaseAppDelegate(){
    /**
     * 适配器
     */
    private var mAdapter:CompleteTaskAdapter?=null
    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_task_correct
    }

    fun initAdapter(mlist: MutableList<CompleteTaskEntity>, isVoice:Boolean){
        val gv_task_atc = getView<NoScrollGridView>(R.id.gv_task_atc)
        mAdapter = CompleteTaskAdapter(getActivity(), mlist,true)
        gv_task_atc.adapter=mAdapter
        if (isVoice){
            gv_task_atc.numColumns=1
        }else{
            gv_task_atc.numColumns=3
        }

    }



    /**
     * 设置老师评价
     */
    fun setEvaluate(good:Boolean,veryGood:Boolean,best:Boolean){
        val iv_atc_good_chose = getView<ImageView>(R.id.iv_atc_good_chose)
        val iv_atc_very_good_chose = getView<ImageView>(R.id.iv_atc_very_good_chose)
        val iv_atc_very_best = getView<ImageView>(R.id.iv_atc_very_best)
        if (good){
            iv_atc_good_chose.isSelected=true
            iv_atc_very_good_chose.isSelected=false
            iv_atc_very_best.isSelected=false
        }else if (veryGood){
            iv_atc_good_chose.isSelected=false
            iv_atc_very_good_chose.isSelected=true
            iv_atc_very_best.isSelected=false
        }else if (best){
            iv_atc_good_chose.isSelected=false
            iv_atc_very_good_chose.isSelected=false
            iv_atc_very_best.isSelected=true
        }


    }


    /**
     * 设置标题栏
     */
    fun setTitle(title:String?){
        val jtb_atc_correct= getView<SKTopBar>(R.id.jtb_atc_correct)
        if (!TextUtils.isEmpty(title)){
            jtb_atc_correct.setTitle(title)
        }
        setEvent(jtb_atc_correct)
    }
    /**
     * 设置设置事件
     */
    private fun setEvent(topBar:SKTopBar){
        val iv_atc_good_chose = getView<ImageView>(R.id.iv_atc_good_chose)
        val iv_atc_very_good_chose = getView<ImageView>(R.id.iv_atc_very_good_chose)
        val iv_atc_very_best = getView<ImageView>(R.id.iv_atc_very_best)
        topBar.setRightTVContent(getActivity<TaskCorrectActivity>().resources.getString(R.string.string_class_submit))
        topBar.setRightTVColor(ContextCompat.getColor(getActivity<TaskCorrectActivity>(),R.color.color_19AD19))
        topBar.getTv_ljtb_right_back()?.visibility= View.VISIBLE
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<TaskCorrectActivity>().finish()
            }
            override fun rightOnClick() {
            if (iv_atc_good_chose.isSelected||iv_atc_very_good_chose.isSelected||iv_atc_very_best.isSelected){

            }else{
               LKToastUtil.showToastShort("请评价")
            }


            }
        })
    }

}